<!--
 * @Author: 张鹏
 * @Date: 2025-07-07 15:00:00
 * @LastEditors: zhangp zhangp@163.com
 * @LastEditTime: 2025-07-07 15:24:40
 * @FilePath: \mapbox\src\components\MapToolbar.vue
 * @Description: 地图工具栏组件
 * 
-->
<template>
    <div class="map-toolbar" :class="{ 'toolbar-collapsed': collapsed }">
        <div class="toolbar-header" @click="toggleCollapse">
            <span class="toolbar-title">{{ title }}</span>
            <el-icon class="collapse-icon">
                <ArrowDown v-if="!collapsed" />
                <ArrowUp v-else />
            </el-icon>
        </div>

        <div class="toolbar-content" v-show="!collapsed">
            <div class="toolbar-section" v-if="showDrawButtons">
                <div class="section-title">绘制工具</div>
                <div class="button-grid">
                    <el-button v-for="btn in drawButtons" :key="btn.type"
                        :type="btn.type === 'primary' ? 'primary' : 'default'" :size="btnSize" @click="btn.onClick"
                        class="toolbar-btn">
                        <el-icon v-if="btn.icon" class="btn-icon">
                            <component :is="btn.icon" />
                        </el-icon>
                        {{ btn.label }}
                    </el-button>
                </div>
            </div>

            <el-divider v-if="showDrawButtons && showControlButtons" />

            <div class="toolbar-section" v-if="showControlButtons">
                <div class="section-title">控制工具</div>
                <div class="button-grid">
                    <el-button v-for="btn in controlButtons" :key="btn.action" :type="btn.type" :size="btnSize"
                        @click="btn.onClick" class="toolbar-btn">
                        <el-icon v-if="btn.icon" class="btn-icon">
                            <component :is="btn.icon" />
                        </el-icon>
                        {{ btn.label }}
                    </el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { ArrowDown, ArrowUp, Delete, View, Hide, Plus, Edit, Location, Aim, Monitor } from '@element-plus/icons-vue'

const props = defineProps({
    title: {
        type: String,
        default: '地图工具栏'
    },
    showDrawButtons: {
        type: Boolean,
        default: false
    },
    showControlButtons: {
        type: Boolean,
        default: true
    },
    drawButtons: {
        type: Array,
        default: () => []
    },
    btnSize: {
        type: String,
        default: 'small'
    }
})

const emit = defineEmits(['draw', 'remove', 'removeAll', 'hideAll', 'showAll'])

const collapsed = ref(false)

const toggleCollapse = () => {
    collapsed.value = !collapsed.value
}

const controlButtons = computed(() => [
    {
        label: '删除',
        action: 'remove',
        type: 'danger',
        icon: Delete,
        onClick: () => emit('remove')
    },
    {
        label: '删除所有',
        action: 'removeAll',
        type: 'danger',
        icon: Delete,
        onClick: () => emit('removeAll')
    },
    {
        label: '隐藏所有',
        action: 'hideAll',
        type: 'warning',
        icon: Hide,
        onClick: () => emit('hideAll')
    },
    {
        label: '显示所有',
        action: 'showAll',
        type: 'success',
        icon: View,
        onClick: () => emit('showAll')
    },
    {
        label: '编辑开关',
        action: 'toggleEdit',
        type: 'info',
        icon: Edit,
        onClick: () => emit('toggleEdit')
    }
])
</script>

<style lang="scss" scoped>
.map-toolbar {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-width: 280px;
    max-width: 400px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    &:hover {
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    }
}

.toolbar-header {
    padding: 16px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s;

    &:hover {
        background-color: rgba(0, 0, 0, 0.02);
    }
}

.toolbar-title {
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
}

.collapse-icon {
    color: #7f8c8d;
    transition: transform 0.2s;
}

.toolbar-content {
    padding: 16px 20px;
}

.toolbar-section {
    margin-bottom: 16px;

    &:last-child {
        margin-bottom: 0;
    }
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    color: #7f8c8d;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.button-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    font-size: 12px;
    border-radius: 8px;
    transition: all 0.2s;
    margin-left: 0;

    &:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

.btn-icon {
    font-size: 14px;
    margin-right: 8px;
    display: inline-flex;
    align-items: center;
}

// 响应式设计
@media (max-width: 768px) {
    .map-toolbar {
        top: 10px;
        left: 10px;
        right: 10px;
        max-width: none;
        min-width: auto;
    }

    .button-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 6px;
    }

    .toolbar-btn {
        height: 32px;
        font-size: 11px;
    }

    .toolbar-content {
        padding: 12px 16px;
    }

    .toolbar-header {
        padding: 12px 16px;
    }
}

@media (max-width: 480px) {
    .button-grid {
        grid-template-columns: 1fr;
    }

    .toolbar-btn {
        justify-content: flex-start;
        padding-left: 12px;
    }
}
</style>